import 'package:boss/models/store_area.dart';
import 'package:boss/provider/table_provider.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/tableManagement/page/areaManagement/page/pickerArea/picker_area_page.dart';
import 'package:boss/ui/page/tableManagement/page/plusBatchTable/provider/plus_batch_table_provider.dart';
import 'package:boss/ui/widget/form/base_text_form_field.dart';
import 'package:boss/ui/widget/form/select_form_field.dart';
import 'package:boss/ui/widget/title_row_button.dart';

import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';

class PlusBatchTableContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: SingleChildScrollView(
        padding: EdgeInsets.symmetric(
          horizontal: 30.w,
        ),
        child: Column(
          children: <Widget>[
            Consumer2<TableProvider, PlusBatchTableProvider>(
              builder: (context, tableProvider, plusBatchTableProvider, _) {
                return TitleRowButton(
                  title: '所属区域',
                  hintText: '请选择',
                  value: plusBatchTableProvider.batchTable?.storeArea?.areaName,
                  onTap: () async {
                    final res = await Navigator.pushNamed(
                      context,
                      PickerAreaPage.pageName,
                      arguments: {'selectedAreaId': plusBatchTableProvider.batchTable?.storeArea?.areaId},
                    );
                    if (res != null) {
                      plusBatchTableProvider.setStoreArea(res);
                    }
                  },
                );
              },
            ),
            BaseTextFormField(
              prefixText: '桌台数量',
              isRequired: true,
              hintText: '请输入批量增加桌台数量',
              keyboardType: TextInputType.number,
              maxLength: 2,
              inputFormatters: [FilteringTextInputFormatter.allow(RegUtil.numberReg)],
              onChanged: (value) {
                var plusBatchTableProvider = Provider.of<PlusBatchTableProvider>(
                  context,
                  listen: false,
                );
                try {
                  plusBatchTableProvider.setTableNumber(int.parse(value));
                } catch (e) {
                  plusBatchTableProvider.setTableNumber(null);
                }
              },
            ),
            BaseTextFormField(
              prefixText: '座位数',
              isRequired: true,
              hintText: '请输入',
              maxLength: 2,
              keyboardType: TextInputType.number,
              inputFormatters: [FilteringTextInputFormatter.allow(RegUtil.numberReg)],
              onChanged: (value) {
                var plusBatchTableProvider = Provider.of<PlusBatchTableProvider>(
                  context,
                  listen: false,
                );
                try {
                  plusBatchTableProvider.setSeatNumber(int.parse(value));
                } catch (e) {
                  plusBatchTableProvider.setSeatNumber(null);
                }
              },
            ),
            Container(
              margin: EdgeInsets.only(
                top: 25.w,
              ),
              child: Text(
                '例：大厅区域，桌台数量2，座位数量4，将批量新增2个4人桌，并命名为：大厅1、大厅2',
                style: TextStyleConstant().normal_4_22,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
